// 翻滚加载(热搜部分)
// 思路;向下翻滚，页数加一，请求发送一次，渲染一次
var currentPage = 1;
// 判断数据是否为0
function judge(data) {
  if (data.transmit == 0) {
    data.transmit = "分享";
  }
  if (data.likes == 0) {
    data.likes = "点赞";
  }
  if (data.comment == 0) {
    data.comment = "评论";
  }
}
function getrestMsg() {
  $(window).scroll(function () {
    if (
      Math.round($(window).scrollTop() + $(window).height()) ==
      $(document).height() - 5
    ) {
      currentPage++;
      $.ajax({
        url: `/weibo/blog/getLoadedTheLatestHotBlog?pageNo=${currentPage}&pageSize=10`,
        type: "get",
        data: {},
        success: function (result) {
          console.log(result);
          let allnews = document.querySelector("#news");
          if (result.length == 10) {
            console.log(result.length);
            for (let i = 0; i < result.length; i++) {
              judge(result[i]);
              allnews.innerHTML += `<div class="news add" uid="${result[i].uid}" bid="${result[i].id}">
          <div class="news-top">
            <a th:href="@{/user/toOnesInfo(id=${result[i].uid})}" class="head-link">
              <div class="head">
                <img
                        src="${result[i].userAvatarUrl}"
                        alt=""
                />
              </div>
            </a>
            <div class="top-details">
              <a href="" class="name">
                <p >${result[i].username}</p>
              </a>
              <p class="time">${result[i].time}</p>
            </div>
            <div class="top-attention">
              <button class="top-attention-btn">
                <i class="iconfont">&#xe7df;</i>关注
              </button>
            </div>
            <div class="report-remove " >
              <div class="rm-icon" th:bid="${result[i].id}" th:otherid="${result[i].uid}" onclick="reportfn(this)"><i class="iconfont">&#xe62e;</i></div>
              <ul class="rm-detials hidden">
                <li class="tip-off-li" th:bid="${result[i].id}">投诉</li>
                <li class="remove-li" th:bid="${result[i].id}">删除</li>
              </ul>
            </div>
          </div>
          <div class="news-container">
            <div  class="container">
              <span class="container-text" >${result[i].text}</span>

              <span class="collapse">收起</span>
            </div>

            <div class="news-content">
            </div>
          </div>
          <!-- 底部博文功能 -->
          <div class="foot">
            <div class="share">
              <i class="iconfont">&#xe62f;</i>
              <span
                      
              >${result[i].transmit}</span
              >
            </div>
            <div class="assess" bid="${result[i].id}">
              <i class="iconfont">&#xe695;</i>
              <span 
              >${result[i].comment}</span
              >
            </div>
            <div class="store">
            <i class="iconfont">&#xe647;</i>
            <span>收藏</span>
          </div>
            <div class="like">
              <i class="iconfont">&#xe62b;</i>
              <span 
              >${result[i].likes}</span
              >
            </div>
          </div>
          <!-- 点击评论展开评论信息 -->
          <div class="spread">
            <textarea
                    placeholder="请发布你的评论"
                    class="comment-text"
            ></textarea>
            <span class="comment-ddl">还可输入140字</span>
            <button class="comment-btn disable">评论</button>
            <!-- 评论 -->
            <div class="comment">
              <!-- 一级评论 -->
              <div class="item1">
                <div class="comment-list">
                  <a href="">
                    <div class="comment-head">
                      <img
                              src="../img/banner.jpg"
                              th:src="@{/static/img/banner.jpg}"
                              alt=""
                      />
                    </div>
                  </a>
                  <div class="comment-details">
                    <a href="" class="comment-name"> <span>XXX</span> </a>:
                    <span class="c-content">今天天气真好1</span>
                    <div class="comment-bottom">
                      <div class="c-time">3-18</div>
                      <div class="comment-fn">
                        <div class="c-complain">
                          <i class="iconfont">&#xe6a9;</i>
                        </div>
                        <div class="reply">
                          <i class="iconfont">&#xe695;</i>
                        </div>
                        <div class="c-like">
                          <i class="iconfont">&#xe600;</i>
                          12
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 二级评论 -->
                <div class="list2">
                  <div class="list2-bar"></div>
                  <div class="list2-details">
                    <a href="" class="list2-name"><span>XXX:</span></a>
                    <span class="list2-content">1111111111</span>
                  </div>
                  <div class="list2-bottom">
                    <div class="list2-time">3-18</div>
                  </div>
                </div>

                <div class="list2">
                  <a class="more-reply"
                  >共2条回复
                    <i class="iconfont">&#xe62e;</i>
                  </a>
                </div>
              </div>
              <!-- 二级评论 -->
            </div>
          </div>
        </div>`;
              let add = document.getElementsByClassName("add")[i];
              let content = add.querySelector(".news-content");
              let picture = result[i].pictureUrl;
              if (picture.length > 0) {
                for (let j = 0; j < picture.length; j++) {
                  content.innerHTML += `<div class="news-content-img"  >
          <img src="${picture[j]}"alt="" onclick="showModel(this)">
        </div>`;
                }
              }
            }
          } else if (result.length > 0 && result.length < 10) {
            for (let i = 0; i < result.length; i++) {
              judge(result[i]);
              allnews.innerHTML += `<div class="news add" uid="${result[i].uid}" bid="${result[i].id}">
          <div class="news-top">
            <a th:href="@{/user/toOnesInfo(id=${result[i].uid})}" class="head-link">
              <div class="head">
                <img
                        src="${result[i].userAvatarUrl}"
                        alt=""
                />
              </div>
            </a>
            <div class="top-details">
              <a href="" class="name">
                <p >${result[i].username}</p>
              </a>
              <p class="time">${result[i].time}</p>
            </div>
            <div class="top-attention">
              <button class="top-attention-btn">
                <i class="iconfont">&#xe7df;</i>关注
              </button>
            </div>
          </div>
          <div class="news-container">
            <div  class="container">
              <span class="container-text" >${result[i].text}</span>

              <span class="collapse">收起</span>
            </div>

            <div class="news-content">
            </div>
          </div>
          <!-- 底部博文功能 -->
          <div class="foot">
            <div class="share">
              <i class="iconfont">&#xe62f;</i>
              <span
                      
              >${result[i].transmit}</span
              >
            </div>
            <div class="assess" th:bid="${result[i].id}">
              <i class="iconfont">&#xe695;</i>
              <span 
              >${result[i].comment}</span
              >
            </div>
            <div class="store">
              <i class="iconfont">&#xe647;</i>
              <span>收藏</span>
            </div>
            <div class="like">
              <i class="iconfont">&#xe62b;</i>
              <span 
              >${result[i].likes}</span
              >
            </div>
          </div>
          <!-- 点击评论展开评论信息 -->
          <div class="spread">
            <textarea
                    placeholder="请发布你的评论"
                    class="comment-text"
            ></textarea>
            <span class="comment-ddl">还可输入140字</span>
            <button class="comment-btn disable">评论</button>
            <!-- 评论 -->
            <div class="comment">
              <!-- 一级评论 -->
              <div class="item1">
                <div class="comment-list">
                  <a href="">
                    <div class="comment-head">
                      <img
                              src="../img/banner.jpg"
                              th:src="@{/static/img/banner.jpg}"
                              alt=""
                      />
                    </div>
                  </a>
                  <div class="comment-details">
                    <a href="" class="comment-name"> <span>XXX</span> </a>:
                    <span class="c-content">今天天气真好1</span>
                    <div class="comment-bottom">
                      <div class="c-time">3-18</div>
                      <div class="comment-fn">
                        <div class="c-complain">
                          <i class="iconfont">&#xe6a9;</i>
                        </div>
                        <div class="reply">
                          <i class="iconfont">&#xe695;</i>
                        </div>
                        <div class="c-like">
                          <i class="iconfont">&#xe600;</i>
                          12
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- 二级评论 -->
                <div class="list2">
                  <div class="list2-bar"></div>
                  <div class="list2-details">
                    <a href="" class="list2-name"><span>XXX:</span></a>
                    <span class="list2-content">1111111111</span>
                  </div>
                  <div class="list2-bottom">
                    <div class="list2-time">3-18</div>
                  </div>
                </div>

                <div class="list2">
                  <a class="more-reply"
                  >共2条回复
                    <i class="iconfont">&#xe62e;</i>
                  </a>
                </div>
              </div>
              <!-- 二级评论 -->
            </div>
          </div>
        </div>`;
              let add = document.getElementsByClassName("add")[i];
              let content = add.querySelector(".news-content");
              let picture = result[i].pictureUrl;
              if (picture.length > 0) {
                for (let j = 0; j < picture.length; j++) {
                  content.innerHTML += `<div class="news-content-img"  >
          <img src="${picture[j]}"alt="" onclick="showModel(this)">
        </div>`;
                }
              }
            }
            allnews.innerHTML += `<p class="none">暂时没有其他内容了</p>`;
          }
          more();
          assessBtn();
          commentfn();
          YesOrNo();
          func();
          replyWindow();
          collapsefn();
          switchoverfn();
        },
      });
    }
  });
}
getrestMsg();
